# Methods added to this helper will be available to all templates in the application.
require 'AuthCheck'
module ApplicationHelper
=begin
Metodo para apresentar as mensagens de erro traduzidas para o portugues.
=end
  def error_messages_for(object_name, options = {})
    options = options.symbolize_keys
    object = instance_variable_get("@#{object_name}")
    unless object.errors.empty?
      items = []
      object.errors.each { |attribute, message| items << content_tag("li", message) }
      content_tag("div",
        content_tag(
        options[:header_tag] || "h2",
        "#{pluralize(object.errors.count, "erro impediu", "erros impediram")} que esse registro fosse salvo:"
        ) +
        content_tag("p", "Os seguintes campos apresentaram problemas:") +
        content_tag("ul", items.join("")),
        "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
      )
    end
  end
  
  def authenticate_check?(exp)
    unless session[:user]
      return false
    else
      logger.debug(AuthCheck.run?(exp, session[:user].capabilite_strs))      
      unless AuthCheck.run?(exp, session[:user].capabilite_strs)
        return false
      end
    end
    return true
  end
  
  def link_to_remote_stylized_confirm(name, message, options = {}, html_options = nil)
    link_to_function(name, "confirm('"+message+"','"+remote_function(options).gsub(/'/,"\\\\'")+"')", html_options || options.delete(:html))
  end
  
end
